package cn.edu.xjtu.work.longestPalindrome;

/**
 * 5. 最长回文子串
 * 
 * 给你一个字符串 s，找到 s 中最长的回文子串。
 */
public class Solution {
  public String longestPalindrome(String s) {
    StringBuilder ret = new StringBuilder("");
    for (int i = 0; i < s.length(); i++) {
      int len = Math.max(i, s.length() - 1);
      StringBuilder sb = new StringBuilder();
      for (int j = 0; j < len; j++) {
        if (s.charAt(i - j) == s.charAt(i + j)) {
          sb.append(s.charAt(i + j));
        } else {
          if (sb.length() > ret.length()) {
            ret = sb;
          } else {
            break;
          }
        }
      }
    }
    
    return null;
  }
}
